home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
17 Bit Software 6: Level 6
/
17 Bit - Level 6 (1998)(Epic Marketing)[!].iso
/
quartz
/
q0039.dms
/
q0039.adf
/
tools
/
ar.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-12-06
|
3KB
|
138 lines
/*
(c) 1990 S.Hawtin.
Permission is granted to copy this file provided that:
1) It is not used for commercial gain
2) This notice is included in all copies
3) Altered copies are marked as such.
No liability is accepted for the contents of the file.
ar.c within Public Domain ar
*/
#include <stdio.h>
#include <ctype.h>
/* This program links object files to create a library, at the moment
this is very simplistic, it just concatenates the object files together,
well it works! */
/* The program should take the names of the files and a -ooutname to
tell us where to put it */
/* Link files together to create a library */
char name[32]="libc.a";
do_o(out)
char *out;
{/* change the output name */
strcpy(name,out);
}
static char sfile[128]="";
do_f(out)
char *out;
{/* Set up the file source */
strcpy(sfile,out);
}
copy_file(from,to)
FILE *from;
FILE *to;
{/* Copy a file */
char temp;
temp = fgetc(from);
while(!feof(from))
{
fputc(temp,to);
temp = fgetc(from);
}
}
do_sfile(out)
FILE *out;
{/* Scan a file for source names */
char name[32];
int i;
FILE *list,*in;
if(*sfile=='\0')
return;
list = fopen(sfile,"r");
while(!feof(list))
{/* Get the next filename */
i=-1;
do{i++;
name[i] = fgetc(list);
}
while(!feof(list) && isgraph(name[i]));
name[i]='\0';
if(i>0)
{in = fopen(name,"r");
if(in == NULL)
{printf("Cannot open %s\n",name);
exit(10);
}
copy_file(in,out);
fclose(in);
}
}
fclose(list);
}
struct _opts
{char ch;
int (*fun)();
} Options[] =
{{'o',do_o},
{'f',do_f},
{'\0'}};
main(argc,argv)
int argc;
char *argv[];
{/* first open the library spec file, passed as the first arg */
FILE *out,*in;
char file_name[128];
int count;
/* Find the output file name in the list */
for(count=1;count<argc;count++)
{if(argv[count][0]=='-')
{int i;
for(i=0;Options[i].ch!='\0' &&
Options[i].ch!=tolower(argv[count][1]);i++);
if(Options[i].ch!='\0')
(*(Options[i].fun))(&argv[count][2]);
else
{printf("ar -ooutfile -fsfile file1 file2 ...\n");
exit(1);
}
}
}
out=fopen(name,"w");
if(out==NULL)
{printf("Cannot open \"%s\" for output\n",name);
exit(1);
}
do_sfile(out);
for(count=1;count<argc;count++)
{if(argv[count][0]!='-')
{char temp;
in = fopen(argv[count],"r");
if(in==NULL)
{printf("Cannot open \"%s\" for input\n",argv[count]);
exit(10);
}
copy_file(in,out);
fclose(in);
}
}
fclose(out);
}